<template>
  <div class="v-eqpt-model-add">
    <c-row-crumb :title="multLang('btn_new_a', 'title_asset_d')">
      <el-button @click="clear">{{ multLang('btn_clear_a') }}</el-button>

      <el-button type="primary" @click="save">
        {{ multLang('btn_save_a') }}
      </el-button>
    </c-row-crumb>
    <el-form
      :model="form"
      :rules="rules"
      ref="form"
      label-width="140px"
      :validate-on-rule-change="false"
    >
      <c-row-add :title="tplLang('title_asset_e', ['title_asset_d'])">
        <c-row :col="4">
          <c-col>
            <el-form-item
              :label="multLang('title_asset_d', ':')"
              prop="model_name"
            >
              <el-input
                v-model="form.model_name"
                :placeholder="multLang('text_d')"
              ></el-input>
            </el-form-item>
          </c-col>
          <c-col>
            <el-form-item
              :label="multLang('title_asset_c', ':')"
              prop="category_id"
            >
              <c-cascader
                v-model="form.category_id"
                :options="assetTypeAllTree"
                :placeholder="tplLang('text_choose_a', ['title_asset_c'])"
              ></c-cascader>
            </el-form-item>
          </c-col>
          <c-col>
            <el-form-item :label="multLang('title_mfr_a', ':')" prop="org_id">
              <c-select
                clearable
                v-model="form.org_id"
                :options="manufacturerList"
                :placeholder="tplLang('text_choose_a', ['title_mfr_a'])"
              ></c-select>
            </el-form-item>
          </c-col>
          <c-col :col="11">
            <el-form-item :label="multLang('title_note_a', ':')" prop="remark">
              <c-input-text v-model="form.remark"></c-input-text>
            </el-form-item>
          </c-col>
        </c-row>
      </c-row-add>
    </el-form>
  </div>
</template>
<script>
import { addAssetModel } from '@/http/api/v1/eqpt-model'
export default {
  name: 'VEqptModelAdd',
  components: {},
  props: {},
  data() {
    return {
      form: {
        model_name: '',
        category_id: '',
        org_id: '',
        remark: ''
      }
    }
  },
  computed: {
    assetTypeAllTree() {
      return this.optionTree('asset_type_all')
    },
    manufacturerList() {
      return this.optionList('manufacturer')
    },
    rules() {
      return {
        model_name: {
          required: true,
          message: this.multLang('title_asset_d', 'msg_g'),
          trigger: 'blur'
        },
        category_id: {
          required: true,
          message: this.tplLang('text_choose_a', ['title_asset_c']),
          trigger: 'change'
        }
      }
    }
  },
  watch: {},
  beforeCreate() {},
  created() {
    this.setOption({ key: 'asset_type_all' })
    this.setOption({ key: 'manufacturer' })
  },
  beforeMount() {},
  mounted() {},
  beforeUpdate() {},
  updated() {},
  activated() {},
  deactivated() {},
  beforeDestroy() {},
  destroyed() {},
  methods: {
    clear() {
      this.$refs.form.resetFields()
    },
    save() {
      this.$refs.form.validate(valid => {
        if (valid) {
          addAssetModel({
            ...this.form
          })
        }
      })
    }
  }
}
</script>
<style lang="scss">
.v-eqpt-model-add {
}
</style>
